package com.xuliugen.security.core.social.wechat.config;

import com.xuliugen.security.core.properties.SecurityProperties;
import com.xuliugen.security.core.social.ConnectView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.web.servlet.View;

/**
 * 微信登录配置
 * Created by xuliugen on 2017/11/7.
 */
@Configuration
@ConditionalOnProperty(prefix = "security.social.wechat", name = "app-id")
public class WeChatAutoConfiguration extends SocialAutoConfigurerAdapter {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    protected ConnectionFactory<?> createConnectionFactory() {
        //TODO 修正代码
//        WeChatProperties properties = securityProperties.getSocial().getWeChatProperties();
//        return new WeChatConnectionFactory(properties.getProviderId(), properties.getAppId(),
//                properties.getAppSecret());

        return null;
    }

    @Bean({"connect/weixinConnect", "connect/weixinConnected"})
    @ConditionalOnMissingBean(name = "weixinConnectedView")
    public View weixinConnectedView() {
        return new ConnectView();
    }

}
